package payroll.classification;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.LinkedHashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

import payroll.Paycheck;
import payroll.PaymentClassification;
import payroll.trans.AddCommissionedEmployeeTransaction;
import payroll.trans.PaydayTransaction;
import payroll.trans.SalesReceiptTransaction;

public class CommissionedClassification implements PaymentClassification{

    private double salary;
    private double commissionRate;
    private Map<String ,SalesReceipt> salesReceipts = new LinkedHashMap<>();

    public CommissionedClassification(double salary, double commissionRate){
        this.salary = salary;
        this.commissionRate = commissionRate;
    }
    
    public double getSalary() {
        return salary;
    }

    public double getCommissonRate() {
        return commissionRate;
    }

    public SalesReceipt getSalesReceiptOfDate(String date) {
        return salesReceipts.get(date);
    }

    public void addSalesReceipt(SalesReceipt sr) {
        salesReceipts.put(sr.getDate(), sr);
         
    }

    @Override
    public double calculatePay() {
        double total = 0.0;     //累计销售额
        for(SalesReceipt sr: salesReceipts.values())
            total += sr.getAmount();

        return salary + total * commissionRate;
    }


}
